import sqlite3
import sys
import json

sys.path.append("..")

from util.parameter import Para
from util.RSImageLocation import GetPixelLongitudeAndLatitude
from active_learning.active_learning import ActiveLearning
from active_learning import al_train_info
from tools.db.db_conn import Connection
from active_learning.al_train import ALTrainFromController

# test
def InitializeSamples(configFileName,rs_name,data_file_name):
    """
    test code! test code! test code!
    """
    para = Para(configFileName)
    with sqlite3.connect(para.db_name) as conn:
        values = list()
        id = 1
        for i in range(8):
            for j in range(5):
                longitude, latitude = GetPixelLongitudeAndLatitude(data_file_name, i, j)
                temp = (id, i, j, latitude, longitude, i)
                values.append(temp)
                id += 1
        sql = "insert into %s_label VALUES(?,?,?,?,?,?)" % rs_name
        conn.executemany(sql, values)


configFileName = "/usr/data/remote_sensing/crowdsourcing_label/tmp/para.config"
para = Para(configFileName)

with sqlite3.connect(para.db_name) as conn:
    rs_name = "test04"
    sql = "select * from %s_label" % rs_name
    cur = conn.execute(sql)
    for line in cur:
        print(line)


"""
dataFileName = "/usr/data/remote_sensing/crowdsourcing_label/rs_images/GF2_shanghai.mat"
InitializeSamples(configFileName, "test01", dataFileName)



alTrainInfoDict = dict()
alTrainInfoDict["rs_name"] = "test01"
alTrainInfoDict["al_iteration_num"] = 5
alTrainInfoDict["label_class_num"] = 8
alTrainInfoDict["now_iteration_num"] = 1
alTrainInfoDict["batch_size"] = 5
alTrainInfoDict["data_file_name"] = "/usr/data/remote_sensing/crowdsourcing_label/rs_images/GF2_shanghai.mat"
alTrainInfoJson = json.dumps(alTrainInfoDict)
ALTrainFromController(alTrainInfoJson, configFileName)
"""

